<?php
/**
 * Created by PhpStorm.
 * User: maqun
 * Date: 2016/2/27
 * Time: 16:56
 */
class SolutionModel extends BaseModel{

    protected $tableName = "solution";//数据库表名


    public function submitSolution($pid,$solution,$language){

        $language_name = C('OJ_LAN_NAME');

        for($i=0;$i<count($language_name);$i++){

            if($language == $language_name[$i]){
                $language=$i;
                break;
            }

        }

        $s_data['problem_id'] = $pid;
        $s_data['user_id']    = $_SESSION['USER']['user_id'];
        $s_data['in_date']    = date('Y-m-d H:i:s',time());
        $s_data['language']   = $language;
        $s_data['ip']         = $_SERVER['SERVER_ADDR'];
        $s_data['code_length']= mb_strlen($solution,'utf-8');

        $insert_id = $this->add($s_data);

        $sc_data['solution_id'] = $insert_id;
        $sc_data['source']      = $solution;
        M('SourceCode')->add($sc_data);
    }
}